//创建用户登录的控制器JS
msqbapp.controller('phoneLoginController',function ($scope,msqbService) {
    //保存用户信息的json对象
    $scope.userBean = {telNumber:'',userPass:''};
    //判断用户的登录信息是否合法
    $scope.isLoginInfo = function () {
        //判断手机号码是否合法
        if (!($scope.userBean.telNumber.match('^1[3456789]\\d{9}$'))){
            alert("手机号码不合法,请重新输入!");
            return false;
        }
        //判断用户密码是否合法
        if (!($scope.userBean.userPass.match('^\\w{6,12}$'))){
            alert("用户密码不合法,请重新输入!");
            return false;
        }
        return true;
    };
    //用户登录
    $scope.login = function () {
        //判断用户的登录信息是否合法
        if($scope.isLoginInfo()){
            //发送用户登录请求
            msqbService.login($scope.userBean).success(function (resp) {
                if(resp.total==0){
                    alert("登陆失败");
                }else{
                    $scope.userBean = resp.rows[0];
                    if($scope.userBean.userNick==null){
                        window.location.href="improve.html?userId="+$scope.userBean.userId;
                    }else{
                        window.location.href="index.html?userId="+$scope.userBean.userId;
                    }
                }
            });
        }
    };
});